home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS6.ZIP / EGAPRINT < prev    next >
Text File  |  1987-01-03  |  6KB  |  216 lines

  1.                       Printing EGA Graphics
  2.          (PC Magazine Vol 6 No 2 Jan 27, 1987 PC Tutor)
  3.  
  4.      The Programming/Utilities columns on the Enhanced Graphics
  5. Adapter ("Exploring the EGA," Vol 5 No 14 and 15) had nothing about
  6. printing EGA graphics displays on the printer.
  7.      The topic of printing EGA graphics displays was avoided since
  8. it's a subject that reveals nothing very interesting about the EGA
  9. itself.  It's principally a printer problem.
  10.      There is no real standard for implementing graphics on printers.
  11. If an EGA graphics screen dump program were to be written, it would
  12. probably be for the IBM Graphics Printer and compatibles, since it's
  13. as close to a standard as exists.  But even IBM Graphics Printers
  14. don't do well printing 16-color graphics.  The printer does not have
  15. enough resolution to use different dot densities for different colors.
  16.      However, if you're doing EGA graphics programming in BASIC, it's
  17. fairly easy to write your own screen dump subroutine to do what you
  18. want it to.  This requires some familiarity with the graphics control
  19. sequences of your printer.  The QuickBASIC 2.0 subroutine below is
  20. one such demonstration program.
  21.  
  22. ' Printing EGA Graphics Screens from QuickBASIC 2.0
  23. '
  24. SCREEN 9                ' Use 10 for EGA on monochrome
  25. FOR I% = 1 TO 100
  26.    CIRCLE (INT(640*RND),INT(350*RND)),INT(100*RND),INT(16*RND)
  27. NEXT I%
  28. CALL PRINTSCREEN
  29. SCREEN 0                ' Restore to normal
  30. END
  31.  
  32. ' PRINTSCREEN Subroutine
  33. '
  34. SUB PRINTSCREEN STATIC
  35.    WIDTH LPRINT 255
  36.    LPRINT
  37.    FOR ROW% = 0 TO 349 STEP 8
  38.       LPRINT CHR$(9); SPC(4);
  39.       LPRINT CHR$(27); "L"; CHR$(128); CHR$(2);
  40.       FOR COL% = 0 TO 640
  41.          BYTE% = 0
  42.          FOR PIXEL% = 0 TO 7
  43.             IF POINT(COL%,ROW%+PIXEL%) > 0 THEN
  44.                BYTE% = BYTE% OR 2^(7-PIXEL%)
  45.             END IF
  46.          NEXT PIXEL%
  47.          LPRINT CHR$(BYTE%);
  48.       NEXT COL%
  49.       LPRINT CHR$(27); "J"; CHR$(24);
  50.    NEXT ROW%
  51. END SUB
  52.  
  53. The top of the program switches to an EGA graphics mode, draws 100
  54. random circles, and then calls the PRINTSCREEN subroutine.
  55.      (You could also write this program in BASICA 3.2 if you added
  56. line numbers and used a GOSUB instead of a CALL.)
  57.      As written, the PRINTSCREEN subroutine works only with the IBM
  58. Graphics Printer and compatibles.  The line:
  59.  
  60. LPRINT CHR$(27); "L"; CHR$(128); CHR$(2);
  61.  
  62. switches to the 120-dot-per-inch graphics mode and prepares the
  63. printer to accept 640 bytes of graphics data.  The horizontal
  64. resolutino of the EGA graphics modes 15 and 16 (represented in BASIC
  65. as 10 and 9) is 640.  The 640 is calculated from the last two numbers
  66. in the CHR$ functions: 640 equals 2 times 256 plus 128.
  67.      Each of the 640 bytes of graphics data sent to the printer
  68. contains 8 bits, 1 for each of 8 vertical pixels.  The byte is
  69. assembled by reading the pixels from the screen using the POINT
  70. function.  Any pixel that is black gets a bit set to 0.  Any pixel
  71. that is not black gets a bit set to 1.  This byte is then sent to
  72. the printer:
  73.  
  74. LPRINT CHR$(BYTE%);
  75.  
  76.      After the whole row of 640 bytes has been sent to the printer,
  77. 8 of the 350 display scan lines have been printed, and it is time to
  78. do a carriage return.  Since the vertical resolution of the IBM
  79. Graphics Printer is 1/72 inch, 8 dots are 1/9 inch high, which means
  80. the line spacing must be 24/216 inch:
  81.  
  82. LPRINT CHR$(27); "J"; CHR$(24);
  83.  
  84. Now it's time for the next 8 rows of pixels.
  85.      Keeping the graphics screen dump in the same BASIC program that
  86. generates the graphics has some significant advantages.  Your program
  87. can control when the screen is printed.  You could pass parameters to
  88. the subroutine to print only part of the screen, or you could print it
  89. over at the left or right of the page and add some text in the margin.
  90.      If you'd rather have a graphics screen dump routine triggered by
  91. Shift-PrtSc, the EGAGRAF.SCR file below creates EGAGRAF.COM with DEBUG.
  92. This is a remain-resident program that works only with the IBM Graphics
  93. Printer and compatibles.  Run:
  94.  
  95. DEBUG < EGAGRAF.SCR
  96.  
  97. EGAGRAF.COM remains resident in memory until you reboot.  When you hit
  98. the Shift-PrtSc combination in video mode 15 (equivalent to BASIC's
  99. mode 9, i.e., EGA 640 by 350 graphics on a monochrome display) or 16
  100. (BASIC's mode 10, i.e., EGA 640 by 350 graphics on an Enhanced Color
  101. Display), the resident program will print the contents of the screen.
  102.      Like the QuickBASIC subroutine shown above, EGAGRAF.COM prints a
  103. dot for every color except the background.  This causes white-on-black
  104. graphics (or, in the case of the monochrome display, green-on-black
  105. graphics) to be printed as black on white.  This reversal of colors is
  106. normal when printing graphics.  If you want black printed as black and
  107. all other colors not printed, change the CMC line to NOP, instead.
  108.  
  109. EGAGRAF.SCR:
  110.  
  111. N EGAGRAF.COM
  112. A
  113. JMP    01C2
  114. DW    00,00
  115. DB    02,0D,0A
  116. DB    09,09,20,20,20,20,1B,4C,80,02
  117. DB    03,1B,4A,18
  118. PUSH    AX
  119. PUSH    BX
  120. PUSH    DS
  121. MOV    AH,0F
  122. INT    10
  123. AND    AL,7F
  124. CMP    AL,0F
  125. JB    0135
  126. CMP    AL,10
  127. JA    0135
  128. MOV    AX,0050
  129. MOV    DS,AX
  130. CMP    BYTE PTR [0000],01
  131. JNZ    013D
  132. POP    DS
  133. POP    BX
  134. POP    AX
  135. CS:
  136. JMP    FAR [0103]
  137. MOV    BYTE PTR [0000],01
  138. STI
  139. PUSH    CX
  140. PUSH    DX
  141. MOV    BX,0107
  142. CALL    0199
  143. SUB    DX,DX
  144. MOV    BX,010A
  145. CALL    0199
  146. SUB    CX,CX
  147. MOV    BX,0800
  148. PUSH    BX
  149. SUB    BH,BH
  150. MOV    AH,0D
  151. INT    10
  152. POP    BX
  153. CMP    DX,015E
  154. JNB    0169
  155. CMP    AL,01
  156. CMC
  157. RCL    BL,1
  158. INC    DX
  159. DEC    BH
  160. JNZ    0158
  161. MOV    AL,BL
  162. CALL    01A8
  163. SUB    DX,+08
  164. INC    CX
  165. CMP    CX,0280
  166. JB    0155
  167. MOV    BX,0114
  168. CALL    0199
  169. ADD    DX,+08
  170. CMP    DX,015E
  171. JB    014D
  172. MOV    BYTE PTR [0000],00
  173. POP    DX
  174. POP    CX
  175. POP    DS
  176. POP    BX
  177. POP    AX
  178. IRET
  179. CS:
  180. MOV    CL,[BX]
  181. SUB    CH,CH
  182. INC    BX
  183. CS:
  184. MOV    AL,[BX]
  185. CALL    01A8
  186. LOOP    019E
  187. RET
  188. PUSH    AX
  189. PUSH    DX
  190. SUB    DX,DX
  191. SUB    AH,AH
  192. INT    17
  193. TEST    AH,29
  194. POP    DX
  195. POP    AX
  196. JZ    01C1
  197. MOV    BYTE PTR [0000],FF
  198. ADD    SP,+02
  199. JMP    0193
  200. RET
  201. MOV    AX,3505
  202. INT    21
  203. MOV    [0103],BX
  204. MOV    [0105],ES
  205. MOV    DX,0118
  206. MOV    AX,2505
  207. INT    21
  208. MOV    DX,01C2
  209. INT    27
  210.  
  211. RCX
  212. DC
  213. W
  214. Q
  215.  
  216.